package main

import (
	"flag"
	"fmt"
	"log"
	"time"
	"zg_four_week3/esclient/internal/config"
	"zg_four_week3/esclient/internal/handler"
	"zg_four_week3/esclient/internal/svc"
	"zg_four_week3/models"

	"github.com/zeromicro/go-zero/core/conf"
	"github.com/zeromicro/go-zero/rest"
)

var configFile = flag.String("f", "etc/esclient-api.yaml", "the config file")

func main() {
	flag.Parse()

	var c config.Config
	conf.MustLoad(*configFile, &c)

	server := rest.MustNewServer(c.RestConf)
	defer server.Stop()

	ctx := svc.NewServiceContext(c)
	handler.RegisterHandlers(server, ctx)

	fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
	go EsMysql("google_bdd") //todo:开启一个协程  同步数据
	server.Start()
}
func EsMysql(index string) {
	//todo: 死循环，只要程序不终止，就会一直生效
	for {
		models.EsMysql(index)
		log.Println("mysql同步es成功")
		//todo: 两分钟更新一次数据
		time.Sleep(time.Hour * 2)
	}

}
